package com.cjm.one.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.cjm.one.common.result.Result;
import com.cjm.one.goods.mapper.GoodsBrowseHistoryMapper;
import com.cjm.one.goods.mapper.GoodsSkuMapper;
import com.cjm.one.goods.service.GoodsBrowseHistoryService;
import com.cjm.one.model.goods.entity.GoodsBrowseHistory;
import com.cjm.one.model.goods.entity.GoodsSku;
import com.cjm.one.model.goods.vo.GoodsSkuBrowseHistoryVo;
import com.cjm.one.model.goods.vo.GoodsSkuVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author 29289
* @description 针对表【goods_browse_history(用户浏览记录表)】的数据库操作Service实现
* @createDate 2025-03-12 21:11:07
*/
@Service
public class GoodsBrowseHistoryServiceImpl extends ServiceImpl<GoodsBrowseHistoryMapper, GoodsBrowseHistory>
    implements GoodsBrowseHistoryService {
    @Resource
    private GoodsBrowseHistoryMapper goodsBrowseHistoryMapper;
    @Resource
    private GoodsSkuMapper goodsSkuMapper;


    @Override
    public Boolean addGoodsBrowseHistory(Long customerId, Long skuId) {
        GoodsBrowseHistory goodsBrowseHistory = new GoodsBrowseHistory();
        LambdaQueryWrapper<GoodsBrowseHistory> goodsBrowseHistoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        goodsBrowseHistoryLambdaQueryWrapper.eq(GoodsBrowseHistory::getCustomId, customerId)
                .eq(GoodsBrowseHistory::getSkuId, skuId);
        if (goodsBrowseHistoryMapper.selectOne(goodsBrowseHistoryLambdaQueryWrapper) != null){
            return false;
        }
        goodsBrowseHistory.setCustomId(customerId);
        goodsBrowseHistory.setSkuId(skuId);
        return goodsBrowseHistoryMapper.insert(goodsBrowseHistory) > 0;
    }

    @Override
    public Boolean deleteBatchGoodsBrowseHistoryByIds(Long[] ids, Long id) {
        LambdaQueryWrapper<GoodsBrowseHistory> goodsBrowseHistoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        goodsBrowseHistoryLambdaQueryWrapper.in(GoodsBrowseHistory::getId, ids)
                .eq(GoodsBrowseHistory::getCustomId, id);
        return goodsBrowseHistoryMapper.delete(goodsBrowseHistoryLambdaQueryWrapper) > 0;
    }

    @Override
    public Page<GoodsSkuVo> listGoodsBrowseHistoryByPage(Long id, Integer current, Integer size) {

        Page<GoodsSkuVo> page = new Page<>(current, size);
        return goodsSkuMapper.selectPageGoodsBrowseHistoryList(page, id);
    }
}




